package dao;
import java.util.List;

import model.users;
import util.TestConnection;
public class DaoProxy implements IUserDAO{
	private TestConnection dbc;
	private IUserDAO dao1;
	public DaoProxy() throws Exception{
		dbc=new TestConnection();
		dao1=new DaoImpl(dbc.getCon());
	}
	public boolean insertUser(users user)throws Exception {
		boolean test=false;
			if(dao1.findById(user.getId())!=null){
				test= dao1.insertUser(user);
			}
			dbc.close();
		return test;
	}
	public boolean updateUser(users user) throws Exception{
		boolean test=false;
			if(dao1.findById(user.getId())!=null){
				test = dao1.updateUser(user);
			}
			dbc.close();
		return test;
	}
	public boolean deleteUser(int Id) throws Exception{
		boolean test=false;
			if(dao1.findById(Id)!=null)
				test = dao1.deleteUser(Id);
			dbc.close();
		return test;
	}
	public List<users> findAll() throws Exception {
		List<users>list = dao1.findAll();
		dbc.close();
		return list;
	}
	public users findById(int Id) throws Exception {
		users user = dao1.findById(Id);
		dbc.close();
		return user;
	}
	public users findByName(String name) throws Exception {
		users user = dao1.findByName(name);
		dbc.close();
		return user;
	}
	@Override
	public boolean IsName(String name) throws Exception {
		boolean test=true;
		test= dao1.IsName(name);
		dbc.close();
		return test;
	}
}